package chinaums.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import chinaums.dao.RulesMapper;
import chinaums.entity.CodeMsg;
import chinaums.service.IRulesService;

/**
 * @author liyongjie
 * @date 2017年6月16日 上午9:21:27
 * @version v1.0
 * @description 主要是对规则编号在页面的展示修改添加及从数据库中读出数据按照要求把数据插入到redis服务器中
 */
@Service
public class RulesServiceimpl implements IRulesService {
	/**
	 * 1,查询全部信息 2,查询数量 3，插入数值 4，修改数值 5，删除数值 6，查询全部备注
	 */
	@Autowired
	private RulesMapper mapper;

	// 查询全部信息
	@Override
	public List<Map<String, Object>> selectalls(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return mapper.selectalls(map);
	}

	// 查询数量
	@Override
	public long rules_count(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return mapper.rules_count(map);
	}

	// 插入数值
	@Override
	public CodeMsg insert_rules(Map<String, Object> param) {
		// TODO Auto-generated method stub
		CodeMsg msg = new CodeMsg();
		long check = mapper.insert_rules(param);
		if (check > 0) {
			msg.setCode("success");
			msg.setMsg("新增成功");
		} else {
			msg.setCode("fail");
			msg.setMsg("新增失败");
		}
		return msg;
	}

	// 修改数值
	@Override
	public CodeMsg update_rule(Map<String, Object> map) {
		CodeMsg msg = new CodeMsg();
		long check = mapper.update_rule(map);
		if (check > 0) {
			msg.setCode("success");
			msg.setMsg("修改成功");
		} else {
			msg.setCode("fail");
			msg.setMsg("修改失败");
		}
		return msg;
	}

	// 删除数值
	@Override
	public CodeMsg delete_rule(Map<String, Object> map) {
		CodeMsg msg = new CodeMsg();
		long check = mapper.delete_rule(map);
		if (check > 0) {
			msg.setCode("success");
			msg.setMsg("删除成功");
		} else {
			msg.setCode("fail");
			msg.setMsg("删除失败");
		}
		return msg;
	}

	// 查询全部备注
	@Override
	public List<Map<String, Object>> select_count() {
		// TODO Auto-generated method stub
		return mapper.select_count();
	}

	/*
	 * @Override public long update_rule(Map<String, Object> map) { // TODO
	 * Auto-generated method stub return mapper.update_rule(map); }
	 */

}
